package gui.components.JXComboBox.JXComboRenderers;

/**
* Date: 12.10.2005
* Time: 19:18:38
*/

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;

public class JXLabelRenderer extends JLabel implements ListCellRenderer, iJXCellRenderer{

    public static final int renderClass = 1;
    public int getRenderClass(){
        return renderClass;
    }

    private HashMap<Integer,Color> rows = new HashMap<Integer,Color>();
    private Color defColor = new Color(255,255,255);
    private int defAlign = JLabel.LEFT;
    private int align = JLabel.CENTER;

    public JXLabelRenderer() {
        setOpaque(true);
        setBackground(defColor);
        setForeground(new Color(0,0,0));
        setHorizontalAlignment(defAlign);
        setFont(new Label().getFont());
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    }

    public void addAlignment(int align){
        this.align = align;
    }

    public void removeAlignment(){
        this.align = defAlign;
    }

    public void addMarkRow(Integer pos, Color color){
        rows.put(pos,color);
    }

    public void removeMarkRow(int pos){
        rows.remove(pos);
    }


    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        setText((value == null) ? "" : value.toString());
        if (rows.containsKey(index)){
            setBackground(rows.get(index));
        }else{setBackground(defColor);}
        if (isSelected){this.setBackground(new Color(89,255,89));}
        //else{this.setBackground(defColor);}
        this.setHorizontalAlignment(align);
        return this;
    }
}
